package com.ly.blog2Word.service.impl;

import com.ly.blog2Common.core.page.MybatisPageHelper;
import com.ly.blog2Common.core.page.PageRequest;
import com.ly.blog2Common.core.page.PageResult;
import com.ly.blog2Word.dao.WordEssayMapper;
import com.ly.blog2Word.dao.model.WordEssay;
import com.ly.blog2Word.service.WordEssayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author: lyMaster
 * @time: 2020/7/17 19:07
 */
@Service
public class WordEssayImpl implements WordEssayService {

    @Autowired
    private WordEssayMapper wordEssayMapper;

    @Override
    public int save(WordEssay record) {
        if(record.getId() == null || record.getId() == 0) {
            return wordEssayMapper.insertSelective(record);
        }
        return wordEssayMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int delete(WordEssay record) {
        return wordEssayMapper.deleteByPrimaryKey(record.getId());
    }

    @Override
    public int delete(List<WordEssay> records) {
        for(WordEssay record:records) {
            delete(record);
        }
        return 1;
    }

    @Override
    public WordEssay findById(Long id) {
        return wordEssayMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageResult findPage(PageRequest pageRequest) {
//        return MybatisPageHelper.findPage(pageRequest, wordEssayMapper);
        return MybatisPageHelper.findPage(pageRequest, wordEssayMapper,"findPageWithMap");
    }

}
